package hu.uniobuda.nik.bsik2f.FileBrowserTest;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import hu.uniobuda.nik.bsik2f.FileBrowser.BrowserActivity;
import hu.uniobuda.nik.bsik2f.FileBrowser.R;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button btnOpenFile = (Button) findViewById(R.id.buttonOpen);
        Button btnSelectDir = (Button) findViewById(R.id.buttonSelectDir);
        Button btnSaveFile = (Button) findViewById(R.id.buttonSaveFile);
        Button btnOpenFileFiltered = (Button) findViewById(R.id.buttonOpenWithFilter);

        final Intent browserIntent = new Intent(this, BrowserActivity.class);

        btnOpenFile.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                browserIntent.putExtra(BrowserActivity.OPTION_BROWSE_MODE, BrowserActivity.MODE_OPEN_FILE);
                startActivityForResult(browserIntent, 0);
            }
        });

        btnSelectDir.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                browserIntent.putExtra(BrowserActivity.OPTION_BROWSE_MODE, BrowserActivity.MODE_SELECT_DIR);
                startActivityForResult(browserIntent, 0);
            }
        });

        btnSaveFile.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                browserIntent.putExtra(BrowserActivity.OPTION_BROWSE_MODE, BrowserActivity.MODE_SAVE_FILE);
                browserIntent.putExtra(BrowserActivity.OPTION_DEFAULT_FILENAME, "test.vmi");
                startActivityForResult(browserIntent, 0);
            }
        });

        btnOpenFileFiltered.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                browserIntent.putExtra(BrowserActivity.OPTION_START_PATH, Environment.getExternalStorageDirectory().getAbsolutePath());
                browserIntent.putExtra(BrowserActivity.OPTION_EXTENSION_FILTER, "mp3;wav");
                browserIntent.putExtra(BrowserActivity.OPTION_START_IS_ROOT, true);
                browserIntent.putExtra(BrowserActivity.OPTION_LAYOUT, BrowserActivity.LAYOUT_GRID);
                startActivityForResult(browserIntent, 0);

            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case 0:
                TextView tvPath = (TextView) findViewById(R.id.textViewPath);
                tvPath.setText(resultCode == RESULT_OK ? data.getStringExtra(BrowserActivity.RESULT) : "Result_Canceled");
                break;
            default:
                break;
        }

    }
}



